package cn.zjk.springframework.aop.framework;

import cn.zjk.springframework.aop.AdvisedSupport;

/**
 * @description:
 * @Author zjk
 * @className: ProxyFactory
 * @date: 2023/4/3 16:25
 */
public class ProxyFactory {
    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy() {
        return createAopProxy().getProxy();
    }

    /**
     * 创建aop策略
     * @return
     */
    private AopProxy createAopProxy() {
        if (advisedSupport.isProxyTargetClass()) {
            return new Cglib2AopProxy(advisedSupport);
        }

        return new JdkDynamicAopProxy(advisedSupport);
    }
}
